<?php
include_once '../../../include/sesion.php';
include_once '../../../include/conexion.php';

$nombre_archivo = 'EXP_CLI-'.date('d-m-y').'.xls';

header("Pragma: ");
header('Cache-control: ');
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=$nombre_archivo");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> 
<head> 
<meta http-equiv="Content-type" content="text/html;charset=iso-8859-1" /> 
<style id="Classeur1_16681_Styles"></style> 
</head> 
<body> 
<div id="Classeur1_16681" align=center x:publishsource="Excel">
<table x:str border=1 cellpadding=0 cellspacing=0 style='border: 3px dotted #00F;border-collapse: collapse' NOWRAP> 
<?php
//-----------------  Datos cotizacion ----------------------------
	$query="SELECT id,[sd],sd_term
      ,[fecha_cotizacion]
      ,[referencia]
      ,[no_cheque]
      ,periodo_pago
      ,[tipo_cuenta],[tamano_inmueble],[giro],[monitoreo],[zonas],[sucursales]
  FROM [sdsmaster].[dbo].[cotizacion] WHERE estado=1";
	$resultado = sqlsrv_query ( $link,$query );
	
while($r = sqlsrv_fetch_array($resultado))
{
	$query2="SELECT [nombre_fact],contacto_fact
      ,[domicilio_fact]
      ,no_int_fact
      ,no_ext_fact
      ,[colonia_fact]
      ,[ciudad_fact]
      ,[cp_fact]
      ,[rfc]
  FROM [datos_cliente] WHERE id_cotizacion=$r[id]";
	$resultado2 = sqlsrv_query ( $link,$query2 );
	//if (!$resultado2) continue 1;
	$dat=sqlsrv_fetch_array($resultado2);

	$fecha_cot=date('d/m/Y',$r['fecha_cotizacion']);
?><tr ><?php 
	echo "
<td>00$r[sd]-$r[sd_term]</td>
<td>$dat[nombre_fact]</td>
<td>$dat[contacto_fact]</td>
<td>$fecha_cot</td>
<td>1</td>
<td>$dat[rfc]</td>
<td width=0></td>
<td width=0></td>
<td>Peso Mexicano</td>
<td width=0></td>
<td width=0>1</td>
<td>$r[tipo_cuenta]</td>
<td>$r[tamano_inmueble]</td>
<td>$r[giro]</td>
<td>$r[monitoreo]</td>
<td width=10>$r[zonas]</td>
<td width=10>$r[sucursales]</td>";
	?>
<td width=0>1</td><td width=0>0</td><td width=0>1</td><td width=0></td><td width=0></td><td width=0></td><td width=0>0</td>
<td width=0></td><td width=0></td><td width=0></td><td width=0></td><td width=0></td><td width=0>
</td><td width=0></td><td width=0></td><td width=0></td><td width=0></td><td width=0></td>
<td width=0></td><td width=0></td><td width=0></td><td width=0></td><td width=0></td><td width=0>
</td><td width=0></td><td width=0></td><td width=0></td><td width=0></td><td width=0></td>
<td width=0></td><td width=0></td><td width=0></td><td width=0></td><td width=0></td>
<?php 
echo "<td>$r[referencia]</td>";
?></tr><?php 
}
?>
</table></div>
</body>
</html>
<?php
cerrar_coneccion($link,$cnn);
?>